package com.newenergy.wisehome.data.bean;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.newenergy.light.Helper.BleDataHelper;

/**
 * Created by dell on 2016/11/29.
 */

@DatabaseTable(tableName = "tb_my_family")
public class Family implements Parcelable {
    @DatabaseField(generatedId = true)
    private int id;
    @DatabaseField(columnName = "familyId")
    private String familyId;

    @DatabaseField(columnName = "blFamilyId")
    private String blFamilyId;

    //BL网关类型 0没有绑定网关 1已经绑定网关
    @DatabaseField(columnName = "blType")
    private int blType = 0;

    @DatabaseField(columnName = "name")
    private String name;
    @DatabaseField(columnName = "type")
    private int type = 1;
    @DatabaseField(columnName = "isChecked")
    private boolean isChecked = false;

    @DatabaseField(columnName = "ballLightCount")
    private int ballLightCount = 0;//当前球泡灯数量

    @DatabaseField(columnName = "fanCount")
    private int fanCount = 0;//当前风扇数量

    @DatabaseField(columnName = "fanLampCount")
    private int fanLampCount = 0;//当前风扇灯数量

    @DatabaseField(columnName = "electricHeaterCount")
    private int electricHeaterCount = 0;//当前电暖气数量

    @DatabaseField(columnName = "bathHeaterCount")
    private int bathHeaterCount = 0;//当前浴霸数量

    @DatabaseField(columnName = "curtainCount")
    private int curtainCount = 0;//当前窗帘数量

    @DatabaseField(columnName = "clotheshorseCount")
    private int clotheshorseCount = 0;//当前晾衣架数量

    @DatabaseField(columnName = "airConditioningCount")
    private int airConditioningCount = 0;//当前空调数量

    @DatabaseField(columnName = "healthBasinCount")
    private int healthBasinCount = 0;//当前养生盆数量

    @DatabaseField(columnName = "deviceCount")
    private int deviceCount = 0;//当前小家电数量

    @DatabaseField(columnName = "seed")
    private int seed = 73;

    @DatabaseField(columnName = "feedback")
    private int feedback = 4777;

    @DatabaseField(columnName = "isHideBallLight")
    private boolean isHideBallLight = false;

    @DatabaseField(columnName = "isHideFanLamp")
    private boolean isHideFanLamp = false;


    @DatabaseField(columnName = "isHideFan")
    private boolean isHideFan = false;


    @DatabaseField(columnName = "isHideBathHeater")
    private boolean isHideBathHeater = false;


    @DatabaseField(columnName = "isHideDataFanLamp")
    private boolean isHideDataFanLamp = false;//是否隐藏风扇灯数据版


    @DatabaseField(columnName = "isHideHumidifier")
    private boolean isHideHumidifier = false;  //是否隐藏加湿器


    //数量
    public Family() {
    }

    public Family(String familyId, String name) {
        this.familyId = familyId;
        this.name = name;
    }

    public Family(String familyId, String name, int ballLightCount) {
        this.familyId = familyId;
        this.name = name;
        this.ballLightCount = ballLightCount;
    }

    public Family(String familyId, String name, int ballLightCount, int seed, int feedback) {
        this.familyId = familyId;
        this.name = name;
        this.ballLightCount = ballLightCount;
        this.seed = seed;
        this.feedback = feedback;
    }


    public Family(String familyId, String name, int ballLightCount, int deviceCount, int seed, int feedback) {
        this.familyId = familyId;
        this.name = name;
        this.ballLightCount = ballLightCount;
        this.deviceCount = deviceCount;
        this.seed = seed;
        this.feedback = feedback;
    }


    public Family(String familyId, String name, int ballLightCount, int fanCount, int fanLampCount, int electricHeaterCount, int bathHeaterCount, int curtainCount, int clotheshorseCount, int airConditioningCount, int healthBasinCount, int seed, int feedback) {
        this.familyId = familyId;
        this.name = name;
        this.ballLightCount = ballLightCount;
        this.fanCount = fanCount;
        this.fanLampCount = fanLampCount;
        this.electricHeaterCount = electricHeaterCount;
        this.bathHeaterCount = bathHeaterCount;
        this.curtainCount = curtainCount;
        this.clotheshorseCount = clotheshorseCount;
        this.airConditioningCount = airConditioningCount;
        this.healthBasinCount = healthBasinCount;
        this.seed = seed;
        this.feedback = feedback;

    }

    public String getFamilyId() {
        return familyId;
    }

    public void setFamilyId(String familyId) {
        this.familyId = familyId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getType() {
        return type;
    }

    public void setChecked(boolean checked) {
        isChecked = checked;
    }

    public boolean isChecked() {
        return isChecked;
    }

    public int getBallLightCount() {
        return ballLightCount;
    }

    public void setBallLightCount(int ballLightCount) {
        this.ballLightCount = ballLightCount;
    }

    public int getSeed() {
        return seed;
    }

    public void setSeed(int seed) {
        this.seed = seed;
    }

    public int getFeedback() {
        return feedback;
    }

    public void setFeedback(int feedback) {
        this.feedback = feedback;
    }

    public int getFanCount() {
        return fanCount;
    }

    public void setFanCount(int fanCount) {
        this.fanCount = fanCount;
    }

    public int getFanLampCount() {
        return fanLampCount;
    }

    public void setFanLampCount(int fanLampCount) {
        this.fanLampCount = fanLampCount;
    }

    public int getElectricHeaterCount() {
        return electricHeaterCount;
    }

    public void setElectricHeaterCount(int electricHeaterCount) {
        this.electricHeaterCount = electricHeaterCount;
    }

    public int getBathHeaterCount() {
        return bathHeaterCount;
    }

    public void setBathHeaterCount(int bathHeaterCount) {
        this.bathHeaterCount = bathHeaterCount;
    }

    public int getCurtainCount() {
        return curtainCount;
    }

    public void setCurtainCount(int curtainCount) {
        this.curtainCount = curtainCount;
    }

    public int getClotheshorseCount() {
        return clotheshorseCount;
    }

    public void setClotheshorseCount(int clotheshorseCount) {
        this.clotheshorseCount = clotheshorseCount;
    }

    public int getAirConditioningCount() {
        return airConditioningCount;
    }

    public void setAirConditioningCount(int airConditioningCount) {
        this.airConditioningCount = airConditioningCount;
    }

    public int getHealthBasinCount() {
        return healthBasinCount;
    }

    public void setHealthBasinCount(int healthBasinCount) {
        this.healthBasinCount = healthBasinCount;
    }


    public int getDeviceCount() {
        return deviceCount;
    }

    public void setDeviceCount(int deviceCount) {
        this.deviceCount = deviceCount;
    }

    public boolean isHideBallLight() {
        return isHideBallLight;
    }

    public void setHideBallLight(boolean hide) {
        isHideBallLight = hide;
    }

    public boolean isHideFanLamp() {
        return isHideFanLamp;
    }

    public void setHideFanLamp(boolean hideFanLamp) {
        isHideFanLamp = hideFanLamp;
    }

    public boolean isHideFan() {
        return isHideFan;
    }

    public void setHideFan(boolean hideFan) {
        isHideFan = hideFan;
    }

    public boolean isHideDataFanLamp() {
        return isHideDataFanLamp;
    }

    public void setHideDataFanLamp(boolean hideDataFanLamp) {
        isHideDataFanLamp = hideDataFanLamp;
    }

    public boolean isHideHumidifier() {
        return isHideHumidifier;
    }

    public void setHideHumidifier(boolean hideHumidifier) {
        isHideHumidifier = hideHumidifier;
    }

    public boolean isHideBathHeater() {
        return isHideBathHeater;
    }

    public void setHideBathHeater(boolean hideBathHeater) {
        isHideBathHeater = hideBathHeater;
    }


    public String getBlFamilyId() {
        return blFamilyId;
    }

    public void setBlFamilyId(String blFamilyId) {
        this.blFamilyId = blFamilyId;
    }

    public int getBlType() {
        return blType;
    }

    public void setBlType(int blType) {
        this.blType = blType;
    }

    @Override
    public String toString() {
        return "Family{" +
                "id=" + id +
                ", familyId='" + familyId + '\'' +
                ", blFamilyId='" + blFamilyId + '\'' +
                ", blType=" + blType +
                ", name='" + name + '\'' +
                ", type=" + type +
                ", isChecked=" + isChecked +
                ", ballLightCount=" + ballLightCount +
                ", fanCount=" + fanCount +
                ", fanLampCount=" + fanLampCount +
                ", electricHeaterCount=" + electricHeaterCount +
                ", bathHeaterCount=" + bathHeaterCount +
                ", curtainCount=" + curtainCount +
                ", clotheshorseCount=" + clotheshorseCount +
                ", airConditioningCount=" + airConditioningCount +
                ", healthBasinCount=" + healthBasinCount +
                ", deviceCount=" + deviceCount +
                ", seed=" + seed +
                ", feedback=" + feedback +
                ", isHideBallLight=" + isHideBallLight +
                ", isHideFanLamp=" + isHideFanLamp +
                ", isHideFan=" + isHideFan +
                ", isHideBathHeater=" + isHideBathHeater +
                ", isHideDataFanLamp=" + isHideDataFanLamp +
                ", isHideHumidifier=" + isHideHumidifier +
                '}';
    }

    /* @Override
         public String toString() {
            return "Family{" +
                    "familyId='" + familyId + '\'' +
                    ", name='" + name + '\'' +
                    ", type=" + type +
                    ", isChecked=" + isChecked +
                    ", ballLightCount=" + ballLightCount +
                    ", seed=" + seed +
                    ", feedback=" + feedback +
                    '}';
        }*/
    public String toQRContent() {
        String seedHex = BleDataHelper.numberToHex(seed);
        String feedbackHex = BleDataHelper.numberToSerial(feedback);
//        return familyId + "&" + name + "&"+ ballLightCount + "&"+seedHex+ "&"+feedbackHex+"[";
       /* return familyId + "&" + name  + "&"+seedHex+ "&"+feedbackHex+ "&"+ ballLightCount+ "&"+ fanCount+ "&"+ fanLampCount+ "&"+ electricHeaterCount+ "&"+ bathHeaterCount
                + "&"+ curtainCount+ "&"+ clotheshorseCount+ "&"+ airConditioningCount+ "&"+ healthBasinCount+"[";*/
         String blContent = "";
        if (!TextUtils.isEmpty(blFamilyId)) {
            blContent = "&" + blFamilyId;
        }
        return familyId + "&" + name + "&" + seedHex + "&" + feedbackHex + "&" + ballLightCount + "&" + deviceCount + blContent + "[";
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.familyId);
        dest.writeString(this.name);
        dest.writeInt(this.type);
        dest.writeByte(this.isChecked ? (byte) 1 : (byte) 0);
        dest.writeInt(this.ballLightCount);
        dest.writeInt(this.fanCount);
        dest.writeInt(this.fanLampCount);
        dest.writeInt(this.electricHeaterCount);
        dest.writeInt(this.bathHeaterCount);
        dest.writeInt(this.curtainCount);
        dest.writeInt(this.clotheshorseCount);
        dest.writeInt(this.airConditioningCount);
        dest.writeInt(this.healthBasinCount);
        dest.writeInt(this.seed);
        dest.writeInt(this.feedback);
        dest.writeInt(this.deviceCount);
    }

    protected Family(Parcel in) {
        this.id = in.readInt();
        this.familyId = in.readString();
        this.name = in.readString();
        this.type = in.readInt();
        this.isChecked = in.readByte() != 0;
        this.ballLightCount = in.readInt();
        this.fanCount = in.readInt();
        this.fanLampCount = in.readInt();
        this.electricHeaterCount = in.readInt();
        this.bathHeaterCount = in.readInt();
        this.curtainCount = in.readInt();
        this.clotheshorseCount = in.readInt();
        this.airConditioningCount = in.readInt();
        this.healthBasinCount = in.readInt();
        this.seed = in.readInt();
        this.feedback = in.readInt();
        this.deviceCount = in.readInt();
    }

    public static final Parcelable.Creator<Family> CREATOR = new Parcelable.Creator<Family>() {
        @Override
        public Family createFromParcel(Parcel source) {
            return new Family(source);
        }

        @Override
        public Family[] newArray(int size) {
            return new Family[size];
        }
    };
}
